<?php
class AdminOptermizeController extends Zone_Action{
	public function indexAction(){}
	
	/*Remove trash from user deleted*/
	public function userAction(){
		$this->removeLayout();
		$users = $this->Model->fetchAll("SELECT * FROM `users` WHERE `is_deleted`='yes'");
		foreach( $users as $a ){
			$this->Model->delete('notices',"`user_id`='{$a['ID']}'");
			$this->Model->delete('calendars',"`created_by_id`='{$a['ID']}' AND `type`='user'");
			if( $a['photo'] ){
				@unlink("files/photo/{$a['photo']}");
			}
		}
	}

	/*Remove old notice*/
	public function noticeAction(){
		$this->removeLayout();
		$this->Model->delete('notices',"CURDATE() > DATE_ADD(DATE(`date`),INTERVAL 1 MONTH)");
	}
	
	/*Optermize table*/
	public function optermizeAction(){
		$this->removeLayout();
		$tables = $this->Model->exec('SHOW TABLES'); 
		$tables = mysql_fetch_assoc($tables);
		
		foreach( $tables as $tb ){ 
		   $this->Model->exec("OPTIMIZE TABLE '$tb'");
		} 
	}
	
}
?>